package com.cetc.stream;

import com.cetc.lambda.Person;
import org.junit.Test;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Classname StreamTest07
 * @Description Collect测试 收集
 * @Date 2023/1/25 19:54
 * @Created by louzhuangxi
 */
public class StreamTest07 {
    /**
     * 测试年龄大于20的员工并将其转换为集合
     */
    @Test
    public void test01() {
        List<Person> personList = Arrays.asList(
                new Person("张三", 24),
                new Person("李四", 80),
                new Person("王五", 28),
                new Person("赵六2", 42),
                new Person("赵六1", 42),
                new Person("田七", 28)
        );
        personList
                .stream()
                .filter(p -> p.getAge() > 20)
                .sorted(Comparator.comparing(Person::getAge))
                .collect(Collectors.toList())
                .forEach(System.out::println);
    }
}
